package com.data.app.controller;

import com.data.app.commons.constant.dto.RestResultData;
import com.data.app.service.ShareDataDisasterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/share")
public class ShareDataController {
    @Autowired
    ShareDataDisasterService shareDataDisasterService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 所有住建数据定时任务
     *
     * @return
     */
    @RequestMapping("/start")
    @Scheduled(cron = "${schedule.cron}")
    public RestResultData shareDataDisaster() {
        // System.out.println("===========开始调用城镇住宅数据");
        // shareDataDisasterService.shareDataCityHouse();
        // System.out.println("==========城镇住宅end");
        //
        // try {
        //     Thread.sleep(20000);
        // } catch (InterruptedException e) {
        // }
        // System.out.println("===========开始调用城镇非住宅数据");
        // shareDataDisasterService.shareDataCityNonHouse();
        // System.out.println("===========城镇非住宅end");//209

        // try {
        //     Thread.sleep(20000);
        // } catch (InterruptedException e) {
        // }
        // System.out.println("===========开始调用农村独立住宅数据");
        // shareDataDisasterService.shareDataCountryDlHouse();
        // System.out.println("===========农村独立住宅数据 end");

        // try {
        //     Thread.sleep(20000);
        // } catch (InterruptedException e) {
        // }
        // System.out.println("===========开始调用农村集合住宅数据");
        // shareDataDisasterService.shareDataCountryJhHouse();
        // System.out.println("===========农村集合住宅数据End");
        //
        // try {
        //     Thread.sleep(20000);
        // } catch (InterruptedException e) {
        // }
        // System.out.println("===========开始调用农村非住宅数据");
        // shareDataDisasterService.shareDataCountryNonHouse();//192
        // System.out.println("===========农村非住宅数据END");
        //
        // try {
        //     Thread.sleep(20000);
        // } catch (InterruptedException e) {
        // }
        // System.out.println("===========开始调用市政桥梁");
        // shareDataDisasterService.shareDataBridge();
        // System.out.println("===========市政桥梁数据END");
        //
        // try {
        //     Thread.sleep(20000);
        // } catch (InterruptedException e) {
        // }
        System.out.println("===========开始调用供水厂数据");
        shareDataDisasterService.shareDataWaterFacility();
        System.out.println("===========供水厂数据END");

        return RestResultData.ok();
    }

    /**
     * 住建数据-城市住宅
     *
     * @return
     */
    @RequestMapping("/city")
    public RestResultData shareDataCityHous() {

        System.out.println("初始化数据！！！");
        //shareDataDisasterService.init();

        System.out.println("===========开始调用城镇住宅数据");
        shareDataDisasterService.shareDataCityHouse();
        System.out.println("==========城镇住宅end");
        return RestResultData.ok();
    }

    /**
     * 住建数据-城市非住宅
     *
     * @return
     */
    @RequestMapping("/city-no")
    public RestResultData shareDataCityNoHous() {

        System.out.println("初始化数据！！！");
        //shareDataDisasterService.init();
        System.out.println("===========开始调用城镇非住宅数据");
        shareDataDisasterService.shareDataCityNonHouse();
        System.out.println("===========城镇非住宅end");
        return RestResultData.ok();
    }

    /**
     * 住建数据-农村独立住宅
     *
     * @return
     */
    @RequestMapping("/country-dl")
    public RestResultData shareDataCountryDlHouse() {

        System.out.println("初始化数据！！！");
        //shareDataDisasterService.init();

        System.out.println("===========开始调用农村独立住宅数据");
        shareDataDisasterService.shareDataCountryDlHouse();
        System.out.println("===========农村独立住宅数据 end");
        return RestResultData.ok();
    }

    /**
     * 住建数据-农村集合住宅
     *
     * @return
     */
    @RequestMapping("/country-jh")
    public RestResultData shareDataCountryJhHouse() {

        System.out.println("初始化数据！！！");
        //shareDataDisasterService.init();

        System.out.println("===========开始调用农村集合住宅数据");
        shareDataDisasterService.shareDataCountryJhHouse();
        System.out.println("===========农村集合住宅数据End");
        return RestResultData.ok();
    }

    /**
     * 住建数据-农村非住宅
     *
     * @return
     */
    @RequestMapping("/country-no")
    public RestResultData shareDataCountryNoHouse() {

        System.out.println("初始化数据！！！");
        //shareDataDisasterService.init();

        System.out.println("===========开始调用农村非住宅数据");
        shareDataDisasterService.shareDataCountryNonHouse();
        System.out.println("===========农村非住宅数据END");
        return RestResultData.ok();
    }

    /**
     * 住建数据-市政桥梁
     *
     * @return
     */
    @RequestMapping("/bridge")
    public RestResultData shareDataBridge() {

        System.out.println("初始化数据！！！");
        //shareDataDisasterService.init();

        System.out.println("===========开始调用市政桥梁");
        shareDataDisasterService.shareDataBridge();
        System.out.println("===========市政桥梁数据END");
        return RestResultData.ok();
    }


    /**
     * 住建数据-供水厂
     *
     * @return
     */
    @RequestMapping("/water")
    public RestResultData shareDataWater() {

        System.out.println("初始化数据！！！");
        //shareDataDisasterService.init();

        System.out.println("===========开始调用供水厂数据");
        shareDataDisasterService.shareDataWaterFacility();
        System.out.println("===========供水厂数据END");
        return RestResultData.ok();
    }
}
